<?php

namespace app\modules\Admin\service;

use app\modules\Admin\models\merchantmenusModel;

class Dianpumenus
{
    public static function getAllChildren(&$rows, $up = 'up', $alias = 'name', $flagPool=[])
    {
        foreach ($rows as $k => &$v) {
            if(merchantmenusModel::query()->where($up, $v->id)->exists()) {
                $v->children = merchantmenusModel::query()->where($up, $v->id)->select( '*', 'id', 'name as ' . $alias)->orderBy('sortorder', 'DESC')->get();
                self::getAllChildren($v->children, 'up', $alias, $flagPool);
            }else {
                $v->checked = in_array($v->id, $flagPool) ? 1 : 0;
            }
        }
    }
}